
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0842
 * @Author : WangRuoyu 
 * @Date : 2023/5/21 16:33
 */

#include "iostream"

using namespace std;

void dfs(bool st[], int nums[], int k, int n) {
    if (k == n) {
        for (int i = 1; i <= n; ++i) {
            printf("%d ", nums[i]);
        }
        printf("\n");
        return;
    } else {
        for (int i = 1; i <= n; ++i) {
            if (!st[i]) {
                st[i] = true;
                nums[k + 1] = i;
                dfs(st, nums, k + 1, n);
                st[i] = false;
            }
        }
    }
}

int main() {
    int n;
    scanf("%d", &n);
    bool st[n + 1];
    int nums[n + 1];
    for (int i = 1; i <= n; ++i) {
        st[i] = false;
        nums[i] = 0;
    }
    dfs(st, nums, 0, n);
    return 0;
}